import Vue from 'vue'
import router from './router'
import {ACCESS_TOKEN} from './store/mutation-types'

router.beforeEach((to, from, next) => {
  if (Vue.ls.get(ACCESS_TOKEN)) {
    // 判断当前的token是否存在
    next()
  } else {
    if (to.fullPath.indexOf('/admin/login') >= 0) {
      next()
    } else {
      next({
        path: '/admin/login',
        query: {redirect: to.fullPath}
      })
    }
  }
})
